package net.gz01.wallet.web.controller.customer;


import com.jfinal.aop.Clear;
import com.jfinal.plugin.activerecord.Page;
import net.gz01.wallet.common.ZOSearchCondition;
import net.gz01.wallet.web.controller.BaseController;
import net.gz01.wallet.web.model.HelpInfo;
import net.gz01.wallet.web.model.MerchUser;

import java.util.List;

@Clear
public class HelpController extends BaseController {

	public void index() {
		MerchUser merchUser = (MerchUser) getSession().getAttribute(MerchUser.SessionKey);

		ZOSearchCondition sc = super.getSearchCondition();
		String pageNum = getPara("p");
		String type = getPara("type");
		if(type == null || "".equals(type)){
			setAttr("currentType","all");
			setAttr("reqPath","/customer/help?p=");
		}else{
			setAttr("currentType",type);
			sc.setParameter("helpType",type);
			setAttr("reqPath","/customer/help?type="+type+"&p=");
		}

		if(pageNum == null || pageNum.equals(""))
			sc.page.setPageNum(1);
		else
			sc.page.setPageNum(Integer.parseInt(pageNum));
		sc.page.setNumPerPage(10);

		Page<HelpInfo> helpPage = HelpInfo.dao.search(sc);
		List<HelpInfo> helpType = HelpInfo.dao.selectHelpType();
		setAttr("helpType",helpType);
		setAttr("helpPage",helpPage);
		if (merchUser == null) {
			render("helpshareList.html");
		}else {
			setAttr("Mysession", merchUser);
			render("helpList.html");
		}
	}

	public void getHelpTitleByKeyWord(){
		String keyword = getPara("keyword");
		List<HelpInfo> helpTitle = HelpInfo.dao.selectHelpTitleByKeyWord(keyword);
		renderJson(helpTitle);
	}

	public void goHelpContentPage() {
		MerchUser merchUser = (MerchUser) getSession().getAttribute(MerchUser.SessionKey);
		String id = getPara("id");
		HelpInfo hi = HelpInfo.dao.findById(id);
		List<HelpInfo> helpType = HelpInfo.dao.selectHelpType();
		setAttr("helpInfo",hi);
		setAttr("helpType",helpType);
		if(merchUser == null){
			render("helpshareDetail.html");
		}else {
			setAttr("Mysession", merchUser);
			render("helpDetail.html");
		}
	}

}
